/*
 * @Author: Vee (547966838@qq.com)
 * @Date: 2024-03-09 13:52:12
 * @LastEditors: Vee (547966838@qq.com)
 * @LastEditTime: 2024-08-20 13:32:28
 * @Descripttion: 
 */
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
// import { exec } from "child_process";

// exec("cd ../TestServer && npm start", (error, stdout, stderr) => {
//   if (error) {
//     console.error(`error: ${error.message}`);
//     return;
//   }
//   if (stderr) {
//     console.error(`stderr: ${stderr}`);
//     return;
//   }
//   console.log(`服务器启动成功`);
// });

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  //获取各环境下的变量
  let env = loadEnv(mode, process.cwd());
  return {
    base: '/',
    plugins: [
      vue(),
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src"),
      },
    },
    server: {
      port: 54360,
      proxy: {
        [env.VITE_APP_BASE_API]: {
          target: env.VITE_SERVE,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
        [env.VITE_AI_CHROMADB_API]: {
          target: env.VITE_AI_CHROMADB_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/chromadb/, ""),
        },
      },
    },
  };
});
